package com.ss.android.wenda.answer.detail2;

import android.content.Context;

import com.bytedance.common.utility.Logger;
import com.bytedance.common.utility.collection.WeakHandler;
import com.ss.android.article.base.app.BizApplication;
import com.ss.android.article.base.feature.app.b.DBHelper;
import com.ss.android.article.base.feature.detail.model.ArticleDetail;
import com.ss.android.article.base.feature.detail.model.ArticleInfo;
import com.ss.android.article.base.feature.detail.presenter.DetailLoader;
import com.ss.android.article.base.feature.detail.presenter.CommentFetcher;
import com.ss.android.article.base.feature.feed.presenter.AnswerQueryUtils;
import com.ss.android.article.base.feature.model.Article;
import com.ss.android.common.load.AsyncLoader;
import com.ss.android.model.AbsArticle;
import java.lang.ref.WeakReference;

public final class a {
    Context a;
    WeakReference b;
    AsyncLoader c;
    AsyncLoader d;
    AsyncLoader e;
    AsyncLoader f;
    private DBHelper g;
    private WeakHandler h;
    private String i;
    private String j;
    private String k;
    private AsyncLoader.LoaderProxy l;
    private AsyncLoader.LoaderProxy m;
    private AsyncLoader.LoaderProxy n;
    private AsyncLoader.LoaderProxy o;

    public a(DetailLoader.Callback arg6, WeakHandler arg7, String arg8, String arg9, String arg10) {

        this.l = new b(this);
        this.m = new com.ss.android.wenda.answer.detail2.c(this);
        this.n = new com.ss.android.wenda.answer.detail2.d(this);
        this.o = new e(this);
        this.a = BizApplication.getApplication();
        this.g = DBHelper.getInstance(this.a);
        this.h = arg7;
        this.i = arg8;
        this.j = arg9;
        this.k = arg10;
        this.b = new WeakReference(arg6);
        this.c = new AsyncLoader(this.l);
        this.d = new AsyncLoader(6, 1, this.m);
        this.f = new AsyncLoader(4, 1, this.o);
        this.e = new AsyncLoader(4, 1, this.n);
    }

    public final void a(String arg3, Article arg4, AbsArticle arg5) {
        this.c.addTask(arg3, arg4, arg5, null);
    }

    static void a(a arg1, Article arg2, AbsArticle arg3, ArticleDetail arg4) {
        Object v0 = arg1.b.get();
        if(v0 != null) {
            ((DetailLoader.Callback)v0).onLoaded(arg2, arg3, arg4);
        }
    }

    final ArticleInfo a(Article arg8, String arg9) {
        ArticleInfo v0;
        ArticleInfo v6 = null;
        if(arg8 == null) {
            v0 = v6;
            return v0;
        }

        try {
            v0 = AnswerQueryUtils.a(this.g, arg8, arg9, this.i, this.j, this.k);
        }
        catch(Throwable v0_1) {
            v0 = v6;
        }

        return v0;
    }

    final ArticleDetail a(AbsArticle arg8, boolean arg9) {
        ArticleDetail v0_1;
        ArticleDetail v6 = null;
        if(arg8 != null && arg8.groupId >= 0) {
            try {
                v0_1 = AnswerQueryUtils.a(this.g, arg8, arg8.groupId, this.j, arg9);
            }
            catch(Throwable v0) {
                Logger.w("AnswerDetailLoader", "get article detail exception: " + v0);
                v0_1 = v6;
            }
        }
        else {
            v0_1 = v6;
        }

        return v0_1;
    }

    public final void a(String arg3, CommentFetcher arg4) {
        this.e.addTask(arg3, arg4, null, null);
    }

    public final void b(String arg5, Article arg6, AbsArticle arg7) {
        int v0 = 1;
        ArticleDetail v3 = android.support.design.a.getDetailCache(arg5);
        if(v3 != null) {
            int v2 = arg6 == null ? 1 : 0;
            if(v2 != 0 && v3.article == null) {
                v0 = 0;
            }

            if(v0 == 0) {
                this.d.addTask(arg5, arg6, arg7, null);
            }else {
                this.h.post(new f(this, arg6, arg7, v3));
            }
        }
        else {
            this.d.addTask(arg5, arg6, arg7, null);
        }
    }

    final ArticleDetail b(AbsArticle arg2, boolean arg3) {
        ArticleDetail v0_1;
        try {
            v0_1 = this.g.queryArticleDetail(arg2, arg3);
        }
        catch(Exception v0) {
            v0_1 = null;
        }

        return v0_1;
    }
}

